//package com.itheima.springboottilasmanager.filter.Test;
//
//import com.itheima.springboottilasmanager.util.JwtUtils;
//import jakarta.servlet.*;
//import jakarta.servlet.annotation.WebFilter;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.IOException;
//@Slf4j
//@WebFilter("/*")
//public class LoginFilter implements Filter {
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
////        1.获取请求路径
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
////        2.判断路径是否是登录路径
//        String res = request.getRequestURL().toString();
//        System.out.println(request.getRequestURL());
//        log.info("filter拦截请求路径，请求路径：{}",request.getRequestURL());
////        如果是登录路径，则放行
//        if(res.contains("/login")){
//            log.info("filter登录请求，放行");
//            filterChain.doFilter(request,response);//执行登录请求
//            return;//注意登录后，会回到过滤器，执行过滤后的操作
//        }
//        //        如果不是登录路径，则获取令牌
//        String token = request.getHeader("token");
////        4.判断令牌是否为空
//        //        4.1如果空,则封装401(401代表未授权)
//if(token==null){
//    log.info("filter令牌为空，返回401");
//    response.setStatus(401);
//    return;
//}
////        如果携带了,则进行解析
//        //        如果解析失败直接封装401
//        try {
//            JwtUtils.parseJWT(token);
//        } catch (Exception e) {
//            log.info("filter令牌解析失败，返回401");
//            response.setStatus(401);
//            return;
//        }
//log.info("filter令牌解析成功，放行");
//        filterChain.doFilter(request,response);
//    }
//}
